<template>
  <div class="hello">
    姓名：<span>{{ name }}</span> <br>

    <button @click="changeName">修改name</button>
  </div>
</template>

<script>
export default {
  name: 'HelloWorld',
  props: {
    msg: String
  },
  data(){
    return {
      age: 18
    }
  },
  computed: {
    name(){
      return this.$store.state.name // 获取Vuex中的数据
    }
  },
  methods: {
    changeName(){
      this.$store.commit('setName', '张三') // 调用Vuex中的mutations中的setName
    }
  }

}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less">
h3 {
  margin: 40px 0 0;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
